var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = "plugin.store-cashier.frontend.store.couponList.index";

Page({
    data: {
        language: "",
        loading: !1,
        allLoaded: !1,
        goload: !0,
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        cupconList: []
    },
    onLoad: function(t) {
        t.id && this.setData({
            store_id: t.id
        }), this.initData(), this.getData();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    initData: function() {
        this.setData({
            loading: !1,
            allLoaded: !1,
            goload: !0,
            isLoadMore: !0,
            page: 1,
            total_page: 0,
            cupconList: []
        });
    },
    getData: function() {
        var t = this, o = a.getNetAddresss(e);
        o += "&store_id=" + this.data.store_id, o += "&page=" + this.data.page, a._getNetWork({
            url: o,
            success: function(a) {
                var e = a.data;
                1 == e.result && t.setData({
                    cupconList: e.data.data,
                    total_page: e.data.last_page
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (!(this.data.page >= this.data.total_page)) {
            t.setData({
                page: this.data.page + 1
            });
            var o = a.getNetAddresss(e);
            o += "&store_id=" + this.data.store_id, o += "&page=" + this.data.page, a._getNetWork({
                url: o,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var o = e.data.data;
                        if (o.length > 0) {
                            var n = t.data.cupconList;
                            t.setData({
                                cupconList: n.concat(o)
                            });
                        } else t.setData({
                            isLoadMore: !1
                        });
                    } else t.setData({
                        page: t.data.page - 1,
                        isLoadMore: !1
                    });
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    getCoupon: function(e) {
        var o = this, n = e.currentTarget.dataset.id, s = e.currentTarget.dataset.index, i = a.getNetAddresss("plugin.store-cashier.frontend.store.couponGet.index");
        i += "&coupon_id=" + n, a._getNetWork({
            url: i,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (o.setData(t({}, "cupconList[" + s + "]", e.data)), wx.showToast({
                    icon: "none",
                    title: "领取成功",
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});